package com.nulldev.util.uri.iwebkit2.document;

import java.util.LinkedList;

public class Document {

	public static Document createDocument(final String url) {
		return new Document(url);
	}
	
	private String url;
	public Document(final String url) {
		this.url = url;
	}
	
	private String title = "";
	
	private final LinkedList<Element> elements = new LinkedList<Element>();

	public void registerElement(final Element element) {
		this.elements.add(element);
	}
	
	public LinkedList<Element> cloneElements() {
		return (LinkedList<Element>) this.elements.clone();
	}
	
	public LinkedList<Element> cloneRenderableElements() {
		final LinkedList<Element> out = (LinkedList<Element>) this.elements.clone();
		for (int i = 0; i < out.size(); i++) {
			final Element x = out.get(i);
			if (x.getElementClass() == ElementClass.SCRIPT
					|| x.getElementClass() == ElementClass.STYLE || x.getElementClass() == ElementClass.TITLE) {
				out.remove(i);
			}
		}
		return out;
	}
	
	public String getTitle() {
		return this.title;
	}
	
	public void setTitle(final String title) {
		this.title = title;
	}
	
	@Override
	public String toString() {
		return "iWebKit2.Document[url=" + this.url + ",title=" + this.title + "]";
	}

}
